
import { combineReducers } from 'redux';
import * as type from '../action/type';

let initStates = {
    panes :[
        { title: 'Tab 1', content: 'Content of Tab Pane 1', key: 'tab1',menuKey:'/app/couPon' },
    ],
    activeKey: "tab1",
};

const panesContent = (state = initStates, action) => {
    switch (action.type) {
        case type.PANES_CONTENT:
            return Object.assign({},state,{
                activeKey:action.activeKey,
                panes:action.panes,
                menuKey:action.menuKey
            });
        default:
            return {...state};
    }
};

const handleData = (state = {isFetching: true, data: {}}, action) => {
    switch (action.type) {
        case type.REQUEST_DATA:
            return {...state, isFetching: true};
        case type.RECEIVE_DATA:
            return {...state, isFetching: false, data: action.data};
        default:
            return {...state};
    }
};
const httpData = (state = {}, action) => {
    switch (action.type) {
        case type.RECEIVE_DATA:
        case type.REQUEST_DATA:
            return {
                ...state,
                [action.category]: handleData(state[action.category], action)
            };
        default:
            return {...state};
    }
};


export default combineReducers({
    httpData,
    panesContent
});
